import 'package:flutter/material.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'package:toys_flutter/components/AuthSpan.dart';
import 'package:toys_flutter/components/LevelSpan.dart';
import 'package:toys_flutter/components/VipSpan.dart';

class UserInfoTop extends StatelessWidget {
  final Map<String, dynamic>? userData; // 存储用户数据的状态变量

  const UserInfoTop({super.key, this.userData});

  @override
  Widget build(BuildContext context) {
    // 提供默认值
    final String avatarUrl = userData?['avatar'] ?? 'images/avatar.png';
    final String nickname = userData?['nickname'] ?? '未设置';
    final String level = userData?['level']?.toString() ?? '1';
    final String sn = userData?['sn'] ?? '未知';

    return Container(
      alignment: Alignment.topLeft,
      margin: const EdgeInsets.all(15),
      child: Row(
        children: [
          Padding(
            padding: const EdgeInsets.fromLTRB(0, 0, 0, 0),
            child: TDAvatar(
              size: TDAvatarSize.large,
              type: TDAvatarType.normal,
              avatarUrl: avatarUrl,
              defaultUrl: 'images/avatar.png',
            ),
          ),
          const SizedBox(width: 10), // 添加间距
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start, // 左对齐
              mainAxisAlignment: MainAxisAlignment.center, // 垂直居中
              children: [
                Row(
                  children: [
                    Text(
                      nickname,
                      style: const TextStyle(fontSize: 14, color: Colors.black),
                    ),
                    const SizedBox(width: 10), // 添加间距
                    const AuthSpan(),
                    const SizedBox(width: 10), // 添加间距
                    LevelSpan(level: level),
                    const SizedBox(width: 10), // 添加间距
                    TDTag(
                      'SN: $sn',
                      shape: TDTagShape.mark,
                      isLight: true,
                      theme: TDTagTheme.warning,
                      size: TDTagSize.small,
                    ),
                  ],
                ),
                const SizedBox(height: 5), // 添加间距
                const Row(
                  children: [
                    Icon(
                      Icons.edit,
                      size: 15,
                    ),
                    SizedBox(width: 2),
                    Text(
                      '编辑信息',
                      style: TextStyle(fontSize: 14, color: Colors.black54),
                    ),
                    SizedBox(width: 10), // 添加间距
                    VipSpan(),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
